<template>
  <div class="pageBox">
    <head-component
      title="金豆"
      rightText="兑换记录"
      @onRightText="onRightText"
    ></head-component>

    <div class="content">
      <div class="useable flex-between">
        <div class="useableLeft flex-center">
          <p>￥{{ balance }}</p>
          <span>可用金豆</span>
        </div>
        <button class="useableRight" @click="goPage('/integralExchange')">
          兑换
        </button>
      </div>

      <div class="titleBox flex-row">
        <div class="line"></div>
        <p>金豆明细</p>
      </div>

      <van-list
        v-model:loading="lBox.loading"
        :finished="lBox.finished"
        @load="onLoad"
      >
        <div class="list">
          <div
            class="listItem flex-between"
            v-for="item in list"
            :key="item.id"
          >
            <div class="listItemLeft flex">
              <p>{{item.remark}}</p>
              <span>{{item.createdAt}}</span>
            </div>
            <div
              class="listItemRight"
              :class="{listItemRightGrey : item.num < 0}"
            >
              ￥{{ Math.abs(item.num) }}
            </div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import { defineComponent, ref } from "vue";
import headComponent from "../../components/headComponent.vue";
import router from "../../router";
import { onLoadList } from "@/setup/loadList.js";
import { post } from "../../untils/request";

export default defineComponent({
  components: {
    headComponent,
  },
  setup() {
    const balance = ref(
      router.currentRoute.value.query.balance
        ? router.currentRoute.value.query.balance
        : ""
    );
    function onRightText() {
      router.push("/interRecord");
    }

    function goPage(url) {
      router.push({
        path: url,
      });
    }

    const { onLoad, list, lBox } = onLoadList({
      form: {
        lastId: 0,
        page: 1,
        creditType: "credit_2",
        direction: "",
      },
      handler: (form) =>
        post("/portal", {
          module: "Finance",
          interface: "2100",
          data: form,
        }),
      afterResponse(res) {
        balance.value = res.creditValue;
      },
    });

    return {
      balance,
      onRightText,
      goPage,
      onLoad,
      list,
      lBox,
    };
  },
});
</script>

<style scoped lang="less">
.pageBox {
  width: 100%;
  min-height: 100vh;
  background-color: #fff;
  padding-top: 88px;
  :deep(.rightTitle) {
    color: #e00b12 !important;
  }
  .content {
    padding: 30px;
    .useable {
      width: 100%;
      height: 180px;
      background: linear-gradient(270deg, #b30b11 0%, #f50811 100%);
      box-shadow: 0px 8px 20px 0px rgba(204, 58, 70, 0.4);
      border-radius: 20px;
      padding: 0 50px 0 70px;

      .useableLeft {
        flex-direction: column;
        align-items: flex-start;
        p {
          font-size: 42px;
          font-weight: 500;
          color: #ffffff;
          margin-bottom: 4px;
        }
        span {
          font-size: 24px;
          font-weight: 400;
          color: #ffffff;
        }
      }
      .useableRight {
        font-size: 28px;
        font-weight: 500;
        color: #e00b12;
        width: 160px;
        height: 64px;
        background: linear-gradient(
          270deg,
          #fbfbfb 0%,
          rgba(245, 245, 245, 0.9) 100%
        );
        border-radius: 30px;
        border: none;
      }
    }
    .titleBox {
      margin-top: 75px;
      margin-bottom: 35px;
      .line {
        width: 6px;
        height: 30px;
        background: #fa4b5a;
        border-radius: 5px;
      }
      p {
        font-size: 32px;
        font-weight: 500;
        color: #17181a;
        margin-left: 8px;
      }
    }
    .list {
      .listItem {
        margin-bottom: 50px;
        .listItemLeft {
          flex-direction: column;
          p {
            font-size: 30px;
            font-weight: 400;
            margin-bottom: 10px;
            color: #333333;
          }
          span {
            font-size: 24px;
            font-weight: 400;
            color: #cccccc;
          }
        }
        .listItemRight {
          font-size: 30px;
          font-weight: 500;
          color: #e00b12;

          &::before{
            content: "+";
          }
        }
        .listItemRightGrey {
          color: #999999;

          &::before{
            content: "-";
          }
        }
      }
    }
  }
}
</style>